package com.zyd.blog.personal.controller;

import com.zyd.blog.business.annotation.BussinessLog;
import com.zyd.blog.personal.service.ProtocolEditService;
import com.zyd.blog.util.ResultUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * 协议编辑
 * @author mfy
 */
@Controller
@RequestMapping("/protocol")
public class ProtocolController {

    @Resource
    private ProtocolEditService protocolEditService;

    /**
     * 进入协议编辑主页面
     * 访问路径 http://localhost:8085/protocol/editor
     * @return  页面
     */
    @BussinessLog("进入协议编辑主页面")
    @RequestMapping("/editor")
    public ModelAndView editor() {
        return ResultUtil.view("/protocol/editor");
    }


    /**
     * 保存协议
     * 访问路径 http://localhost:8085/protocol/saveProtocol
     * @return  结果
     */
    @RequestMapping("/saveProtocol")
    @ResponseBody
    public boolean saveProtocol(String type,String content){
        return protocolEditService.updateProtocol(type,content);
    }

    /**
     * 得到协议内容
     * 访问路径 http://localhost:8085/protocol/getProtocol?type=test
     * @param type  协议类型
     * @return  协议内容
     */
    @RequestMapping("/getProtocol")
    @ResponseBody
    public String getProtocol(String type){
        return protocolEditService.getProtocol(type);
    }


}
